<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<html>
  <head>
    <base href="<%=basePath%>">
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/edittable.css"/>
    <link rel="stylesheet" type="text/css" href="css/validate.css"/>
    <script type="text/javascript" src="js/jquery-1.8.0.js"></script>
    <script type="text/javascript" src="js/validate.js"></script>
	
    <script>
        $(function () {
            $("input[type=text],textarea").focus(function () {
                $(this).addClass("input_focus");
            }).blur(function () {
                $(this).removeClass("input_focus");
            });

            $(".form_btn").hover(function () {
                    $(this).css("color", "red").css("background", "#6FB2DB");
                },

                function () {
                    $(this).css("color", "#295568").css("background", "#BAD9E3");
                });
		
		//验证用户名
		function validateAdminName() {
            var reg = /[a-zA-Z0-9]{4,15}/g;
            var adminName = $("#adminName").val();
            if (reg.test(adminName)) {
                $.ajax({
                    url: "AdminServlet.do",
                    type: "POST",
                    data: {adminName: $("#adminName").val(),flag:"validate"},
                    success: function (data) {
                       if(data==-1){
                           $("#adminName_msg").removeClass().addClass("validate_error").html("用户名已存在");
                           return false;
                       }else {
                           $("#adminName_msg").removeClass().addClass("validate_ok").html("✓");
                           return true;
                       }
                    }
                });
            } else {
                $("#adminName_msg").removeClass().addClass("validate_error").html("用户名格式不正确");
                return false;
            }
        }

		//验证密码
        function validatePassword() {
            var result=false;
            var reg = /[a-zA-Z0-9]{6,20}/g;
            var password = $("#password").val();
            if (reg.test(password)) {
                result = true;
                $("#password_msg").removeClass().addClass("validate_ok").html("✓");
            } else {
                $("#password_msg").removeClass().addClass("validate_error").html("密码格式不正确");
            }
            return result;
        }

		//验证重复密码
        function validatePwdconfirm() {
            var result=false;
            var password = $("#password").val();
            var pwdconfim = $("#pwdconfirm").val();
            if(pwdconfim==""){
                $("#pwdconfirm_msg").removeClass().addClass("validate_error").html("重复密码不能为空");
            }else {
                if (password == pwdconfim) {
                    result = true;
                    $("#pwdconfirm_msg").removeClass().addClass("validate_ok").html("✓");
                } else {
                    $("#pwdconfirm_msg").removeClass().addClass("validate_error").html("两次密码输入不一致");
                }
            }
            return result;
        }

        $("#adminName").blur(function () {
         validateAdminName();
        });
        $("#password").blur(function () {
            validatePassword();
        });
        $("#pwdconfirm").blur(function () {
            validatePwdconfirm();
        });
        $(".form_btn").click(function () {
            var result=true;
            if (validateAdminName()==false) {
               result=false;
            }
            if(validatePassword()==false){
                result=false;
            }
            if(validatePwdconfirm()==false){
                result=false;
            }
            if(result==true){
                return confirm("请确认提交");
            }
            return result;
        });

    });
</script>

</head>
<body>
	<div class="div_title">
	<div class="div_titlename"><img src="images/san_jiao.gif"><span>管理员添加</span></div>
	</div>
	<form action="AdminServlet.do" method="post">
		<input type="hidden" name="flag" value="add">
		<table class="edit_table">
		    <tr>
		        <td class="td_info">用户账号:</td>
		        <td class="td_input_short">
		            <input type="text" class="txtbox" id="adminName" name="adminName" value="${param.adminName}"/>
		        </td>
		        <td>
		            <label class="validate_info" id="adminName_msg">4-15位；只限数字(0-9)和英文(a-z),不区分大小写</label>
		        </td>
		    </tr>
		    <tr>
		        <td class="td_info">用户密码:</td>
		        <td>
		            <input type="text" class="txtbox" name="password" id="password" value="${param.password}"/>
		        </td>
		        <td><label class="validate_info" id="password_msg">数字或英文,6-20位</label></td>
		    </tr>
		    <tr>
		        <td class="td_info">重复密码:</td>
		        <td><input type="text" class="txtbox" id="pwdconfirm" value="${param.password}"/>
		        </td>
		        <td><label class="validate_info" id="pwdconfirm_msg">请重复输入密码</label></td>
		    </tr>
		    <tr>
		        <td class="td_info">备注信息:</td>
		        <td><textarea rows="4" cols="27" name="note" class="txtarea">${param.note}</textarea></td>
		        <td><label></label></td>
		    </tr>
		    <tr>
		        <td class="td_info"></td>
		        <td>
		            <input class="form_btn" type="submit" value="提交"/>
		            <input type="reset" class="form_btn" value="重置"/></td>
		        <td>
		            <label id="result_msg" class="result_msg">${msg}</label>
		        </td>
		    </tr>
		</table>
	</form>
</body>
</html>
